<template>
  <div class="row">
    <div class="title">{{ title }}</div>
    <div class="content" @click="select">
      <span
        v-if="value"
        :class="disabled ? 'disabled ellipsis' : 'black ellipsis'"
        >{{ value }}</span
      >
      <span v-else class="tip">{{ tip }}</span>
      <span v-if="!disabled" class="option">选择</span>
    </div>
    <van-popup v-model="show" position="bottom" :round="true">
      <van-datetime-picker
        v-model="currentDate"
        type="date"
        title="选择年月日"
        visible-item-count="3"
      />
      <div class="btn_box">
        <button class="btn large" @click="submitTime">确定</button>
      </div>
    </van-popup>
  </div>
</template>

<script>
import { ParseDate } from '@/utils'

export default {
  name: 'inputItemTime',
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    // 标题
    title: {
      type: String,
      default: ''
    },
    // 内容
    value: {
      type: String,
      default: ''
    },
    // 提示
    tip: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      show: false,
      currentDate: new Date()
    }
  },
  created() {},
  methods: {
    select() {
      if (this.disabled) return false
      this.show = true
    },
    submitTime() {
      this.show = false
      let formatTime = ParseDate(this.currentDate)
      this.$emit('input', formatTime)
    }
  }
}
</script>

<style lang="scss" scoped>
// input禁用-样式
input:disabled {
  background-color: #fff;
  color: #656c74;
}
.black {
  color: #171819;
}
.disabled {
  color: #656c74;
}
.row {
  .title {
    font-family: PingFang SC Regular;
    font-size: 14px;
    font-weight: normal;
    line-height: 19px;
    letter-spacing: 0px;
    color: #171819;
  }

  .content {
    font-family: PingFang SC Regular;
    font-size: 16px;
    font-weight: normal;
    letter-spacing: 0px;
    color: #171819;
    position: relative;
    height: 38px;
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;

    &::after {
      content: '';
      width: 100%;
      height: 0.5px;
      background: #e2e7ec;
      position: absolute;
      left: 0;
      bottom: 0;
    }

    .tip {
      font-family: PingFang SC Regular;
      font-size: 14px;
      font-weight: normal;
      line-height: 19px;
      letter-spacing: 0px;
      color: #b2b8bd;
    }

    .option {
      font-family: PingFang SC Medium;
      font-size: 14px;
      font-weight: normal;
      line-height: 19px;
      letter-spacing: 0px;
      /* 蓝 */
      color: #2163e0;
      flex-shrink: 0; // 禁止自动压缩
    }
  }

  &:last-child {
    .content {
      margin-bottom: 0;

      &::after {
        display: none !important;
        height: 40px;
      }
    }
  }
}
</style>
